<?php
/**
 * ElecTarrif actions.
 *
 * @package    utility
 * @subpackage ElecTarrif
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class ElecTarrifActions extends sfActions
{
public function executeIndex(sfWebRequest $request)
  {
    $this->forward('ElecTarrif', 'list');
  }
  
  public function executeList()
  {
	  $c = new Criteria();
	  $c->add(ElecTarrifPeer::STATUS, Constant::RECORD_STATUS_DELETED, Criteria::NOT_EQUAL);
	  $c->addAscendingOrderByColumn(ElecTarrifPeer::ID);
	  $this->tarrifs = ElecTarrifPeer::doSelect ($c);
  } // - END - executeList 

public function executeAdd(sfWebRequest $request)
  {
  	if ($request->isMethod('Post'))
  	{
		$tariff = new ElecTarrif();
		
		$tariff->setTitle($this->getRequestParameter('title'));
		$tariff->setFromUnit($this->getRequestParameter('from_unit'));
		$tariff->setToUnit($this->getRequestParameter('to_unit'));
		$tariff->setCivilRate($this->getRequestParameter('civil_rate'));
		$tariff->setRebateRate($this->getRequestParameter('rebate_rate'));
		$tariff->setOfficerRate($this->getRequestParameter('officer_rate'));
		$tariff->setStatus(Constant::RECORD_STATUS_ACTIVE);
		
		$tariff->save();
		$this->getUser()->setFlash('SUCCESS_MESSAGE', Constant::RECORD_ADDED_SUCCESSFULLY);
		$this->redirect ('ElecTarrif/list');
	} //end if
  } // - END - executeAdd
  
 
public function executeEdit (sfWebRequest $request)
	{

		if ($this->getRequest()->getMethod() == sfRequest::POST)
		{
			$tariff = ElecTarrifPeer::retrieveByPk($this->getRequestParameter('id'));

			$tariff->setTitle($this->getRequestParameter('title'));
			$tariff->setFromUnit($this->getRequestParameter('from_unit'));
			$tariff->setToUnit($this->getRequestParameter('to_unit'));
			$tariff->setCivilRate($this->getRequestParameter('civil_rate'));
			$tariff->setRebateRate($this->getRequestParameter('rebate_rate'));
			$tariff->setOfficerRate($this->getRequestParameter('officer_rate'));
			
			if($tariff->save())
			{
				$this->getUser()->setFlash('SUCCESS_MESSAGE', Constant::RECORD_EDITED_SUCCESSFULLY);
				$this->redirect ('ElecTarrif/list');
			}
			else
			{
				$this->getUser()->setFlash('ERROR_MESSAGE', Constant::DB_ERROR);
				$this->redirect('ElecTarrif/edit?id='.Utility::EncryptQueryString($request->getParameter('id')));
			}
		}

		else
		{
			$this->tariff = ElecTarrifPeer::retrieveByPk(Utility::DecryptQueryString($request->getParameter('id')));
		}
	} //- END - executeEdit
  
public function executeDelete (sfWebRequest $request)
	{
		$tariff = ElecTarrifPeer::retrieveByPk(Utility::DecryptQueryString($request->getParameter('id')));

		if($tariff)
		{
			$tariff->setStatus(Constant::RECORD_STATUS_DELETED);
			if(	$tariff->save())
			$this->getUser()->setFlash('SUCCESS_MESSAGE', Constant::RECORD_STATUS_DELETED_SUCCESSFULLY);
			else
			$this->getUser()->setFlash('ERROR_MESSAGE', Constant::DB_ERROR);
		}
		else
		{
			$this->getUser()->setFlash('ERROR_MESSAGE', Constant::INVALID_REQUEST);
		}
	
		$this->redirect ('ElecTarrif/list');
	} //- END - executeDelete

}
